/**
 * Copyright 2021 Solomon. All rights reserved.
 * Date : 2021.03.24
 */

#include "./inc/spd2010_common.h"

#include "./inc/spd2010_fw_update.h"
#include "./inc/spd2010_i2c.h"

/*******************************/
/* I2C_Write                    */
/*******************************/
uint8_t I2C_Write(uint8_t *wbuf, uint16_t wlen)
{
    tp_spd2012_cmd_t write;
    if(wlen > sizeof(write))
    {
        LOG0("[TP]: spd2012 write data too long");
        return false;
    }
    memcpy(&write.reg,wbuf,wlen);
    uint32_t ret = TP_APP_SPD2012_WRITE_BYTES( write.reg, write.data, wlen-2 );//-2 is because +2 in macro
    if( ret != TP_I2C_SUCCESS)
    {       
        LOG1("[TP]: spd2012 w err = 0x%X", ret );
    }
    return ret == TP_I2C_SUCCESS; 
}

/*******************************/
/* I2C_Read                    */
/*******************************/
uint8_t I2C_Read(uint8_t *rbuf, uint16_t rlen)
{
    uint32_t ret = TP_APP_SPD2012_READ_BYTES(  rbuf, rlen) ;
    if( ret != TP_I2C_SUCCESS)
    {       
        LOG1("[TP]: spd2012 r err = 0x%X", ret );
    }
    return ret == TP_I2C_SUCCESS; 
}
